﻿using Dx.Models.Models;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Dx.Common
{
    /// <summary>
    /// 静态公共参数
    /// </summary>
    public class ParametersBaseHelper
    {
        /// <summary>
        /// 缓存文件缓存到内存中，一个项目大概十来M静态文件，完全可以缓存到内存重
        /// <para>key：文件物理路径。value：文件流</para>
        /// </summary>
        public static ConcurrentDictionary<string, MemoryStream> DicCacheInMemo = new ConcurrentDictionary<string, MemoryStream>();
        /// <summary>
        /// 内存缓存web截图，用户打开窗口无感
        /// </summary>
        public static ConcurrentDictionary<string, Bitmap> DicWebShot = new ConcurrentDictionary<string, Bitmap>();
        /// <summary>
        /// Webview2支持的最低版本
        /// <para>16.0.13127.20082</para>
        /// </summary>
        public static readonly System.Version LowestVersion = new System.Version("16.0.13127.20082");

        /// <summary>
        /// 电脑宽度
        /// </summary>
        public static readonly int WindowWidth = Screen.PrimaryScreen.Bounds.Width;

        /// <summary>
        /// 电脑高度
        /// </summary>
        public static readonly int WindowHeight = Screen.PrimaryScreen.Bounds.Height;

        /// <summary>
        /// 项目运行的目录
        /// </summary>
        public static readonly string BaseDirectoryPath = AppDomain.CurrentDomain.BaseDirectory;

        /// <summary>
        /// 用户配置文件路径(不能适配其他项目，考虑更换配置文件名称)
        /// </summary>
        public static readonly string UserSettingIniPath = BaseDirectoryPath + "markbook.ini";

        /// <summary>
        /// 前端地址
        /// </summary>
        public static string FrontURL = "";

        /// <summary>
        /// 后端地址
        /// </summary>
        public static string BackendURL = "";

        /// <summary>
        /// 当前项目对应的token
        /// </summary>
        public static string Token = FuncBaseHelper.DESDecrypt(FuncBaseHelper.GetIniValue("User", "sign"));

        /// <summary>
        /// 是否开启Debug模式，1开启，0关闭
        /// </summary>
        public static bool IsDebugModel = true;

        /// <summary>
        /// 批量上传接口地址(:魏鹏)
        /// </summary>
        public static string UploadFilesURL = "/compilation/file/uploads";

        /// <summary>
        /// 批量上传接口地址(中转地址:鸿泰)
        /// </summary>
        public static string UploadFilesURLV1 = "/compilation/client/uploadFile";

        /// <summary>
        /// 设备编码（机器码）
        /// </summary>
        public static string DeveiceCode = FuncBaseHelper.GetCpu() + FuncBaseHelper.GetHDID().Replace(" ", "").Replace("-", "");

        /// <summary>
        /// 项目名称
        /// </summary>
        public static string ApplicationName = "快书编标";

        /// <summary>
        /// 是否配置添加水印
        /// </summary>
        public static bool IsNeedWaterMark = false;

        /// <summary>
        /// 配置水印模块 1：全部 2：文本 3：图片
        /// </summary>
        public static int ApplyWaterMarkModel = 0;

        /// <summary>
        /// 配置水印应用类型 0,1：使用自定义文本 2：根据所选项目来走（每次使用之前将当前所选项目重新赋值到界面）
        /// </summary>
        public static int ApplyWaterMarkType = 0;

        /// <summary>
        /// 后端配置水印信息
        /// </summary>
        public static WaterMarkInfo WaterMarkConfigInfo = new WaterMarkInfo();

        /// <summary>
        /// 文件对应的文件类型
        /// </summary>
        public readonly static Dictionary<string, byte[]> FileSignatures = new Dictionary<string, byte[]>()
        {
            { "JPEG", new byte[] { 0xFF, 0xD8, 0xFF } },
            { "PNG", new byte[] { 0x89, 0x50, 0x4E, 0x47 } },
            { "GIF", new byte[] { 0x47, 0x49, 0x46, 0x38 } },
            { "PDF", new byte[] { 0x25, 0x50, 0x44, 0x46, 0x2D } },
            { "ZIP", new byte[] { 0x50, 0x4B, 0x03, 0x04 } },
            { "DOC", new byte[] { 0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1 } }, // Compound File Binary Format
            { "XLS", new byte[] { 0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1 } }, // Compound File Binary Format
            { "PPT", new byte[] { 0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1 } }  // Compound File Binary Format
        };

        /// <summary>
        /// 授权码
        /// </summary>
        internal readonly static string Register = "<License><Data><LicensedTo>Fluor Federal Services</LicensedTo><EmailTo>t.j.tumlin@fluor.com</EmailTo><LicenseType>Site Small Business</LicenseType>"
            + "<LicenseNote>Limited to 10 physical locations, not to exceed 10 developers</LicenseNote><OrderID>190501090513</OrderID><UserID>412577</UserID>"
            + "<OEM>This is not a redistributable license</OEM><Products><Product>Aspose.Total for .NET</Product></Products><EditionType>Enterprise</EditionType>"
            + "<SerialNumber>57cbdcb5-e657-4ed1-aed2-b2613bdd3517</SerialNumber><SubscriptionExpiry>20210106</SubscriptionExpiry><LicenseVersion>3.0</LicenseVersion>"
            + "<LicenseInstructions>https://purchase.aspose.com/policies/use-license</LicenseInstructions></Data>"
            + "<Signature>GNczbuoKwEEKCQJaQlTugFt30pBwgAEfPAfICZ6v6+CE+ABgm6cblP8I/KMqJiWFAMTf1/jRXR61SqKRFppFl+W1rvnd26YX9fQkI3b/4Vq2JHDr15cZbFNxHmRAAjW6W/bGRcfVBsnIG8XsD7yrp8146G8zbyX2BJ05JTCT2Yc=</Signature>"
            + "</License>";
    }
}
